package com.honeywen.mymvc.leetcode;


import java.util.ArrayList;
import java.util.List;

/**
 * 6. Z 字形变换
 * https://leetcode-cn.com/problems/zigzag-conversion/
 *
 * @author wangwei
 * @date 2020/10/24
 */
public class ConvertTest {


    public String convert2(String s, int numRows) {






        return null;
    }



    public String convert(String s, int numRows) {
        List<List<String>> result = new ArrayList<>();

        // 每一行都加一个list
        for (int i = 0; i < numRows; i++) {
            result.add(new ArrayList<>());
        }

        // 然后拆分字符串，

        int min = 0;
        int max = numRows - 1;
        int index = 0;
        boolean flag = true;
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            result.get(index).add(String.valueOf(ch));

            if (index == max) {
                flag = false;
            }

            if (index == min) {
                flag = true;
            }

            //
            if (min == max) {
                continue;
            }


            if (flag) {
                index++;
            } else {
                index--;
            }

        }

        StringBuilder sb = new StringBuilder();
        result.forEach(i -> i.forEach(j -> sb.append(j)));

        return sb.toString();
    }


    public static void main(String[] args) {
        ConvertTest test = new ConvertTest();
       /* System.out.println(test.convert("LEETCODEISHIRING", 3));
        System.out.println("LCIRETOESIIGEDHN");
        System.out.println("------");
        System.out.println(test.convert("LEETCODEISHIRING", 4));
        System.out.println("LDREOEIIECIHNTSG");*/
//        System.out.println("------");
        System.out.println(test.convert("AB", 1));
//        System.out.println("AB");
    }


}
